<template>
	<view>
		<view class="swiperBox">
			<u-swiper :list="swiperList" previousMargin="30" nextMargin="30" circular :autoplay="false" radius="5"
				bgColor="#f5f5f5" height="433" @click="clickSwiper" imgMode="widthFix" indicator indicatorMode="dot"
				indicatorActiveColor="#1B6AFF" indicatorInactiveColor="#CDCDCD"></u-swiper>
		</view>

		<view class="activityContent">
			<home-title @more="goMoreActivity" title="活动列表" :showMore="true"></home-title>

			<activity-item v-for="(item, index) in activityList" :key="item.activityId" :activityInfo="item"
				@goActivityDetail="configTemplateView"></activity-item>
		</view>

		<!-- <coupon-dialog></coupon-dialog> -->

		<!-- 底部导航 -->
		<HomeTabbar :tab="0"></HomeTabbar>
	</view>
</template>

<script>
	import HomeTabbar from '@/components/tabbar/tabbar';
	import homeTitle from '@/components/layout/home-title.vue';
	import activityItem from '@/pages/activity/components/activity-item.vue'
	import couponDialog from '@/components/dialog/coupon-dialog.vue'
	import settings from '@/settings.js'
	import {
		apiActivityCarouseArea,
		apiActivityListArea
	} from '@/api/activity-api.js'
	export default {
		components: {
			HomeTabbar,
			homeTitle,
			activityItem,
			couponDialog
		},
		data() {
			return {
				swiperActivityList: [],
				swiperList: [],
				activityList: []
			}
		},
		onLoad() {
			wx.showShareMenu({
				withShareTicket:true,
			  menus: ['shareAppMessage']
			})
			this.getCarouseData();
			this.getActivityListData();
		},
		methods: {
			// 获取轮播图卡片
			getCarouseData() {
				apiActivityCarouseArea({
					tenantId: this.$store.state.user.tenantId
				}).then(res => {
					let data = res.data;
					this.swiperActivityList = data;
					data.forEach(item => {
						let url = settings.baseImageUrl + item.coverPictures;
						this.swiperList.push(url);
					})

				})
			},
			// 获取活动列表
			getActivityListData() {
				apiActivityListArea({
					tenantId: this.$store.state.user.tenantId,
					pageNo: 1,
					pageSize: 5
				}).then(res => {
					this.activityList = res.data;

				})
			},

			clickSwiper(index) {
				let activityItem = this.swiperActivityList[index];
				this.configTemplateView(activityItem);

			},
			// 配置活动模板
			configTemplateView(activityItem) {
				let templateCode = activityItem.templateCode;
				switch (templateCode) {
					case 'YHQ-001': //优惠券模板
						uni.navigateTo({
							url: '/pagesB/activity/template/coupon?activityId=' + activityItem.activityId
						})
						break;
					case 'CX-001': //车型模板
						uni.navigateTo({ 
							url: '/pagesB/activity/template/car?activityId=' + activityItem.activityId
						})
						break;
					case 'ZQ-CX-001': //中秋节车型模板
						uni.navigateTo({
							url: '/pagesB/activity/template/zhongqiu-car?activityId=' + activityItem.activityId
						})
						break;
					case 'ZQ-SQ-001': //中秋节优惠券模板
						uni.navigateTo({
							url: '/pagesB/activity/template/zhongqiu-coupon?activityId=' + activityItem.activityId
						})
						break;
					default:
						break;
				}
			},
			goMoreActivity() {
				uni.navigateTo({
					url: './activity-more'
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.swiperBox {}

	.activityContent {
		margin: 0rpx 34rpx 20rpx;
	}
</style>
